package cn.com.bluemoon.bd.flink.common;

import com.alibaba.fastjson.JSONObject;

public enum OperType {
    INSERT(1), UPDATE(2), DELETE(3), NULL(0);
    private int value;
	
	private OperType(int value) {
		this.value = value;
	}
	
	public boolean isInsert() {
		if (this == INSERT) return true;
		return false;
	}
	
	public boolean isUpdate() {
		if (this == UPDATE) return true;
		return false;
	}
	
	public boolean isDelete() {
		if (this == DELETE) return true;
		return false;
	}

    public int getValue() {
        return value;
    }

	public static OperType type(String operType) {
		if (null == operType) {
			return NULL;
		} else if (operType.equals("I")) {
			return INSERT;
		} else if (operType.equals("U")) {
			return UPDATE;
		} else if (operType.equals("D")) {
			return DELETE;
		} else {
			return NULL;
		}
	}
	
	public static OperType type(JSONObject jsonObj) {
		String operType = jsonObj.getString("canal_oper_type");
		return OperType.type(operType);
	}

	public static void main(String[] args) {
		System.out.println(OperType.type("D").isDelete());
		System.out.println(OperType.type("I"));
	}
	
}
